/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.smarttv.model;

import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.yonsei.iwb.smarttv.model.measure.PropertyWeight;
import java.util.Vector;

/**
 *
 * @author parklize
 */
public class MArc {
//    private final Resource property;
//    private final String name;
    private final double weight;
    private boolean direction;
    private boolean selected;
    
    private MNode head;
    private MNode tail;
    private Property property;
    
    private PropertyWeight pw;
    
    private MArc parentArc;
    private Vector<MArc> childArcs;
    
    public MArc(PropertyWeight pw) {
        this.pw = pw;
//        this.name = "";
        this.weight = pw.getWeight();
        this.selected = false;
    }
    
    public MArc(MNode h, MNode t, Property p, double w, boolean d){
        this.head = h;
        this.tail = t;
        this.property = p;
        this.weight = w;
        this.direction = d;        
    }
    
    public MNode getHeadNode(){
        if(direction){
            return this.head;
        }else{
            return this.tail;
        }
    }
    
    public MNode getTailNode(){
        if(direction){
            return this.tail;
        }else{
            return this.head;
        }
    }
    
    public boolean getDirection(){
        return this.direction;
    }
    
    public Property getProperty(){
        return this.property;
    }
    
    public Vector<MArc> getChild() {
        return childArcs;
    }

    public MArc getParent() {
        return parentArc;
    }

    public void setChild(Vector<MArc> child) {
        this.childArcs = child;
    }

    public void setParent(MArc parent) {
        this.parentArc = parent;
    }
    
    public void addChild(MArc child){
        this.childArcs.add(child);
    }
    
    public PropertyWeight getPw() {
        return pw;
    }
    
    
    public Property getPropertyURI(){
        return this.pw.getProperty();
    }

    public double getWeight() {
        return this.weight;
    }
    
    public void setSelected(boolean selected) {
        this.selected = selected;
    }
    public boolean isSelected() {
        return this.selected;
    }
    
    @Override
    public String toString(){
        StringBuffer sb = new StringBuffer();
        
        try{
            sb.append(this.getHeadNode().getNode().getLocalName());
            if(this.getDirection()){
                sb.append(" --> ");                
            }else{
                sb.append(" <-- ");
            }
            sb.append(this.getProperty().getLocalName());    
            if(this.getDirection()){
                sb.append(" --> ");                
            }else{
                sb.append(" <-- ");
            }
            sb.append(this.getTailNode().getNode().getLocalName());
            sb.append("  W = ");
            sb.append(this.getWeight());
            sb.append("\n");
        }catch(NullPointerException e){
            sb.append(this.getHeadNode().getNode().getLocalName());
            sb.append(" --> ");    
            sb.append(this.getTailNode().getNode().getLocalName());
        }
        
        
        return sb.toString();
    }
}
